extends ../layout

block content
  .container
    .row
      .col-md-7
        if movie.flash
          embed(src="#{movie.flash}", allowFullScreen="true", quality="high", width="600", height="400")
        else
          img(src="#{movie.poster}",width="720")
        .panel.panel-defatul
          .panel-heading
            h3 评论区
          .panel-body
            ul.media-list
              if comments && comments.length>0
                each item in comments
                  li.media
                    .pull-left
                      a.comment(href="#comments", data-cid="#{item._id}", data-tid="#{item.from._id}")
                        img.media-object(src="", style="width: 64px; height: 64px;")
                    .media-body
                      h4.media-heading #{item.from.name}
                      p #{item.content}
                      if item.reply && item.reply.length > 0
                        each reply in item.reply
                          .media
                            .pull-left
                              a.comment(href="#comments", data-cid="#{item._id}", data-tid="#{reply.from._id}")
                                img.media-object(src="", style="width: 64px; height: 64px;")
                            .media-body
                              h4.media-heading
                                | #{reply.from.name}
                                span.text-info &nbsp;回复&nbsp;
                                | #{reply.to.name}:
                              p #{reply.content}
                    hr
            #comments
              form#commentForm(method="POST", action="/user/comment")
                input(type="hidden", name="comment[article]", value="#{article._id}")
                if user
                  input(type="hidden", name="comment[from]", value="#{user._id}")
                  input#toId(type="hidden", name="comment[tid]")
                  input#commentId(type="hidden", name="comment[cid]")
                .form-group
                  textarea.form-control(name="comment[content]", row="3")
                if user
                  button#submit.btn.btn-primary(type='submit') 提交
                else
                  a.navbar-link(href="#", data-toggle="modal", data-target="#signinModal") 登录后评论
      .col-md-5
        .dl-horizontal
          dt 电影名字
          dd= movie.title
  script.
    $(function() {
      $('.comment').click(function(e) {
        var target = $(this)
        var toId = target.data('tid')
        var commentId = target.data('cid')
        $('#toId').val(toId)
        $('#commentId').val(commentId)
      })
      $("#submit").click(function(e){
        e.preventDefault()
        $.ajax({
          type:'post',
          data: $('#commentForm').serialize(),
          url: '/user/comment'
        }).done(function(results){
          if(results.success == 1){
            window.location.reload()
          }
        })
      })
    })